package net.adetech.crj.dao;


import net.adetech.crj.entity.Apply;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ApplyMapper {

    @Select("select a.*,b.appointment_id from CRJ_APPLY a,(select * from CRJ_APPOINTMENT where state = '1') b where a.apply_id = b.apply_id(+) and a.APPLY_USER_ID = #{applyUserId}  and apply_summary = #{applySummary} and a.DATA_STATE = '1' order by a.apply_time desc")
    List<Apply> getApplyListByApplyUserId(@Param("applyUserId") String applyUserId,@Param("applySummary") String applySummary);

    @Select("select * from CRJ_APPLY where ID_NUMBER = #{idNumber} and DATA_STATE = '1'")
    List<Apply> getApplyListByIdNumber(String idNumber);


    @Select("select * from CRJ_APPLY where APPLY_NO = #{ywbh} and DATA_STATE = '1'")
    Apply getApplyByYwbh(String ywbh);

    @Select("select * from CRJ_APPLY where APPLY_ID = #{applyId} and DATA_STATE = '1'")
    Apply getApplyById(String applyId);


    @Insert("insert into crj_apply (apply_id, apply_user_id, id_type, id_number,phone_number, real_name, apply_no ,apply_summary, apply_detail, apply_time, apply_state, data_state,remind_json) " +
            "values(SEQ_CRJ_APPLY_APPLY_ID.NEXTVAL, #{applyUserId}, #{idType}, #{idNumber},#{phoneNumber}, #{realName}, #{applyNo}, #{applySummary}, #{applyDetail}, sysdate, '1', '1',#{remindJson}) ")
    void saveApply(Apply apply);



    @Select("select a.*,b.appointment_id from CRJ_APPLY a,(select * from CRJ_APPOINTMENT where state = '1') b where a.apply_id = b.apply_id(+) and a.ID_NUMBER = #{idNumber} and  a.APPLY_USER_ID = #{applyUserId} and a.DATA_STATE = '1' order by a.apply_time desc")
    List<Apply> getApplyListByIdNumberAndApplyUserId(@Param("idNumber") String idNumber,@Param("applyUserId") String applyUserId);


    @Update("update CRJ_APPLY set DATA_STATE = #{state} where ID_NUMBER = #{idNumber} and  APPLY_USER_ID = #{applyUserId} and DATA_STATE = '1'")
    void updateApplyStateByIdNumberAndApplyUserId(@Param("idNumber") String idNumber,@Param("applyUserId") String applyUserId,@Param("state") String state);





}
